var toast = require("../../../components/toast/toast.js")
var app = getApp()
var tsCount = 10;
Page({
    data: {
        btn_loading: false,
        moreHide: "hide",
        allList: [],
        list: []
    },
    getOrderList: function (e) {
        let _this = this;

        var param = {
            api: 'Service.UcOrder.OrderService.GetOrders',
            url: '/wx/carViola/getOrders.ajax',
	          para: {
		          'bizFlag': '3',
		          'orderType': 1
            }
        };

        app.requestSdkForNeedLogin({
            param: param,
            beforeSend: () => {
                //发送请求之前执行
                wx.showToast({
                    title: '请稍候',
                    icon: 'loading',
                    duration: 10000,
                    mask: true
                });
            },
            success: data => {
                console.log('订单列表',data)
                if (data.code == 1000) {
                    let orderList = data.body.orderList;
                    let moreHide = "hide";
                    let showList = [];
                    let endIndex = orderList.length;
                    if (endIndex > tsCount) {
                        endIndex = tsCount;
                        moreHide = "";
                    }
                    for (let j = 0; j < endIndex; j++) {
                        showList.push(orderList[j]);
                    }
                    _this.setData({
                        "allList": orderList,
                        "list": showList,
                        "moreHide": moreHide
                    })

                } else {
                    toast.show(this, data.errormsg)
                }
            },
            complete: data => {
                wx.hideToast();
            }
        });
    },
    //点击更多
    addOrder: function (e) {
        this.setData({
            "btn_loading": true
        })
        var moreHide = "";
        var showList = this.data.list;
        var orderList = this.data.allList;
        var nextIndex = showList.length + tsCount;
        var endIndex = orderList.length;
        if (nextIndex >= endIndex) {
            nextIndex = endIndex;
            moreHide = "hide";
        }
        for (var i = showList.length; i < nextIndex; i++) {
            showList.push(orderList[i]);
        }
        this.setData({
            "btn_loading": false,
            "list": showList,
            "moreHide": moreHide
        })
    },
    //调转到订单确认页面
    orderDetails: function (e) {
        var orderId = e.currentTarget.dataset.orderid;
        wx.navigateTo({
            url: '../orderDetails/orderDetails?orderId=' + orderId
        })

    },
    onLoad: function (options) {
        this.getOrderList();
    },
    onReady: function () {
        wx.setNavigationBarTitle({ title: "我的订单" })
    },
    onShow: function () {
        wx.setNavigationBarTitle({ title: "我的订单" })
    },
    onShareAppMessage: function () {
        return {
            title: '还在为违章处理排队烦恼吗？',
            desc: '车行易查违章，免费查询，实时提醒，快速在线缴罚款，车主最贴心的车务管家！ ',
            path: 'pages/carInfo/list/list'
        }
    }
})